import Vue from 'vue'
import Router from 'vue-router'
/*登录组件*/ 
import Login from '@/components/login/login.vue'
/*后台首页组件*/ 
import Home from '@/components/home/home.vue'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import axios from 'axios'
axios.defaults.baseURL="http://localhost:8888/api/private/v1/"
Vue.prototype.$http =axios

Vue.use(ElementUI);
Vue.use(Router)
 const router =new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    }
  ]
})

/*路由守卫*/
router.beforeEach((to,from,next)=>{
  const token =window.sessionStorage.getItem('token')
  if(token!==null && to.path==='/'){
   return next('/')
  }
  next()
})
export default router